from flask import Flask, render_template, request, send_from_directory, render_template_string
from pyecharts.render import make_snapshot, snapshot

from WeatherXM.service.dataShow import get_chart

app = Flask(__name__, static_folder="static", template_folder='templates')


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/getdata", methods=['GET'])
def get_weather_data():
    city = request.args.get('city')
    page = get_chart(city)

    # page.render('page.html')
    # print(a.dump_options_with_quotes())

    # return send_from_directory('../', 'page.html') # 成功

    # return render_template('page1.html', chart=page.render_embed()) # 失败

    chart = page.render_embed()
    
    return render_template_string(chart)


if __name__ == "__main__":
    app.run()
